home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / IWF12.ZIP / MODULES / SAMP_DLG.C < prev    next >
C/C++ Source or Header  |  1994-01-22  |  5KB  |  190 lines

  1. /*
  2. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3. SAMPDLG.C
  4.  
  5. AUTHOR: Craig Muller P. Eng. 1991,1992,1993
  6.         cmuller@ccu.umanitoba.ca
  7.         Computer Vision Laboratory
  8.         Mech. Engn.,Univ. of Manitoba
  9.         Winnipeg, Manitoba. R3T 2N2
  10.  
  11. DESCRIPTION:
  12. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  13. */
  14. #include <windows.h>
  15.  
  16. #pragma hdrstop
  17.  
  18. #include <stdio.h>
  19. #include <string.h>
  20.  
  21. #include "iwf.h"
  22.  
  23. // Defines.
  24. #define  MODULENAME "SAMPDLG"
  25.  
  26. // Exported Procedures.
  27. BOOL FAR PASCAL _export DP_SampDlg(HWND hDlg,WORD wMsg,WORD wParam,LONG lParam);
  28.  
  29. // Private variables.
  30. HWND  hDlgSampDlg=NULL;
  31.  
  32. static HINSTANCE hInstance;              // Application instance handle.
  33.  
  34. /*
  35. --------------------------------------------------------------------------
  36. SampDlg()
  37. ~~~~~~~~
  38.  
  39. SAMPDLG STARTUP PROCESSING PROCEDURE.
  40. This is called when the user selects this option from the main menu.
  41. This procedure check to see if the popup window exists. If so it simply
  42. passes focus to the window and returns since there is nothing more to do.
  43. If it does not exist then it proceeds to create the popup window and menu
  44. and displays it on the screen. The popup window acts like a sub-program
  45. within the main program and receives messages from the main program.
  46. --------------------------------------------------------------------------
  47. */
  48. void SampDlg(HWND hWndParent)
  49.    {
  50.    FARPROC lpProc;
  51.    RECT rc0,rc1;
  52.    int w,h;
  53.  
  54.    if (IsWindow(hDlgSampDlg))
  55.       {
  56.       SetFocus(hDlgSampDlg);
  57.       }
  58.    else
  59.       {
  60.       hInstance = GetWindowWord(hWndParent,GWW_HINSTANCE);
  61.       lpProc = MakeProcInstance(DP_SampDlg,hInstance);
  62.       hDlgSampDlg = CreateDialog(hInstance,MODULENAME,hWndParent,lpProc);
  63.       GetWindowRect(hWndParent,&rc0);
  64.       GetWindowRect(hDlgSampDlg,&rc1);
  65.       w = rc1.right - rc1.left;
  66.       h = rc1.bottom - rc1.top;
  67.       MoveWindow(hDlgSampDlg,rc0.right-10-w,rc0.top+45,w,h,TRUE);
  68.       }
  69.    }
  70.  
  71.  
  72.  
  73.  /*
  74. ===============================================================================
  75. BOOL FAR PASCAL _export DP_SampDlg(HWND hDlg,WORD wMsg,WORD wParam,LONG lParam)
  76.  
  77. Decription:
  78. This window procedure handles all the messaging for the SampDlg Image Viewing
  79. module. Special code is called which produces a red and blue composite
  80. image from both left and right grey scale image. The user the puts on red
  81. and blue 3D glasses to view the image in 3D.
  82. ===============================================================================
  83. */
  84. BOOL FAR PASCAL _export DP_SampDlg(HWND hWnd,WORD wMsg,WORD wParam,LONG lParam)
  85.    {
  86.    switch (wMsg)
  87.       {
  88.       case WM_INITDIALOG:                        // WINDOW CREATION.
  89.       PostMessage(hWnd,WM_USER,0,0);             // Ready to show the window
  90.       break;
  91.  
  92.       case WM_USER:
  93.       ShowWindow(hWnd,SW_SHOW);                  // Show the window
  94.         hWndMod = hWnd;                            // Make this module active.
  95.       break;
  96.  
  97.       case WM_CTLCOLOR:
  98.       switch(HIWORD(lParam))
  99.          {
  100.          case CTLCOLOR_STATIC:
  101.          SetBkColor((HDC)wParam,GetSysColor(COLOR_BTNFACE));
  102.          return (LRESULT) GetStockObject(LTGRAY_BRUSH);
  103.          }
  104.       return (LRESULT) NULL;
  105.  
  106.       case WM_PAINT:                             // IMAGE NEEDS PAINTING.
  107.       {
  108.       RECT rc;
  109.       PAINTSTRUCT ps;
  110.  
  111.       BeginPaint(hWnd,&ps);
  112.  
  113.       if (IsIconic(hWnd))
  114.          {
  115.          DrawIcon(ps.hdc,0,0,LoadIcon(hInstance,"SAMPDLG"));
  116.          }
  117.       else
  118.          {
  119.          GetClientRect(hWnd,&rc);
  120.          FillRect(ps.hdc,&rc,GetStockObject(LTGRAY_BRUSH));
  121.          }
  122.  
  123.       EndPaint(hWnd,&ps);                        // Painting complete.
  124.       }
  125.       break;
  126.       
  127.       case WM_LBUTTONUP:                         // LEFT BUTTON UP.
  128.         case WM_RBUTTONUP:                         // RIGHT BUTTON UP.
  129.         {
  130.         HDC hDC;
  131.         char sz[80];
  132.         int scale;
  133.         RECT rc;
  134.         IMAGE *image;
  135.  
  136.         hDC = GetDC(hWnd);
  137.         GetClientRect(hWnd,&rc);
  138.         rc.bottom = 100;
  139.         FillRect(hDC,&rc,GetStockObject(LTGRAY_BRUSH));
  140.         SetBkColor(hDC,GetSysColor(COLOR_BTNFACE));
  141.         if (IsWindow((HWND)wParam))
  142.             {
  143.             image = GetImage((HWND)wParam);
  144.             scale = GetScale((HWND)wParam);
  145.             sprintf(sz,"Message from image window");
  146.             TextOut(hDC,10,10,sz,strlen(sz));
  147.             sprintf(sz,"File: %s",image->fspec);
  148.             TextOut(hDC,10,25,sz,strlen(sz));
  149.             sprintf(sz,"Scale: %d  Width: %d  Height: %d",scale,image->hres,image->vres);
  150.             TextOut(hDC,10,40,sz,strlen(sz));
  151.             }
  152.         else
  153.             {
  154.             sprintf(sz,"Message from user window");
  155.             TextOut(hDC,10,10,sz,strlen(sz));
  156.             hWndMod = hWnd;                            // Make this module active.
  157.             }
  158.         ReleaseDC(hWnd,hDC);
  159.         }
  160.         break;
  161.  
  162.         case WM_LBUTTONDBLCLK:
  163.         hWndMod = hWnd;                            // Make this module active.
  164.         break;
  165.  
  166.         case WM_CHAR:
  167.       case WM_COMMAND:                           // MENU COMMAND SELECTED.
  168.         break;
  169.  
  170.         case WM_SETFOCUS:                          // FOCUS HAS BEEN SET.
  171.       hWndMod = hWnd;                            // Make this module active.
  172.       break;
  173.  
  174.       case WM_KILLFOCUS:                         // FOCUS HAS BEEN KILLED.
  175.       break;
  176.  
  177.       case WM_CLOSE:
  178.       DestroyWindow(hWnd);
  179.       break;
  180.  
  181.       case WM_DESTROY:
  182.       break;
  183.       }
  184.  
  185.    lParam=lParam;
  186.  
  187.    return(NULL);
  188.    }
  189.  
  190.